/**
 *
 */
package st.yushao.restaurant.action.waitor;

import java.util.List;

import st.yushao.restaurant.dao.UserDaoService;
import st.yushao.restaurant.fw.AbstractBaseAction;
import st.yushao.restaurant.vo.UserVO;

import com.opensymphony.xwork2.ActionContext;

/**
 * @author acer
 *
 */
public class WaitorLogin extends AbstractBaseAction {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 7382433632321298865L;

    private String userName;
    private String pwd;
    private UserDaoService uds = null;
//    private RestDaoService rds = null;
    public String doExecute() {
        ActionContext ac = ActionContext.getContext();
        UserVO userVO = (UserVO) ac.getSession().get(KEYS.CUR_USER);
        // already login
        if (userVO != null) {
            return SUCCESS;
        }
        // get the information of current user
        List<UserVO> uvoLst = uds.getUserByName(userName, pwd);
        if (uvoLst == null || uvoLst.size() != 1) {
            return INPUT;
        }
        // set the current user in session
        UserVO uvo = uvoLst.get(0);
        ac.getSession().put(KEYS.CUR_USER, uvo);
        // get the current restaurant
//        int restId = uvo.getRestId();
//        RestaurantVO restVO = rds.getRestById(restId);
//        ac.getSession().put(KEYS.CUR_REST_KEY, restVO);
        return SUCCESS;
    }

//    public void setRds(RestDaoService rds) {
//        this.rds = rds;
//    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public UserDaoService getUds() {
        return uds;
    }
    public void setUds(UserDaoService uds) {
        this.uds = uds;
    }

}
